//
//  MyOrderViewPageVc.m
//  WGFGlobalHouses
//
//  Created by welldone on 15/5/18.
//  Copyright (c) 2015年 waiguofang. All rights reserved.
//

#import "MyOrderViewPageVc.h"
#import "MyOrderSubVc.h"
#import "BdTV.h"
#import "config.h"
#import "NSString+category.h"

@interface MyOrderViewPageVc ()<ViewPagerDataSource, ViewPagerDelegate>
@property (nonatomic,strong)UILabel *lable1,*lable2,*lable3;

@end



@implementation MyOrderViewPageVc
@synthesize lable1,lable2,lable3;

- (void)viewDidLoad {
    [self initView];
    [super viewDidLoad];
}

-(void)initView{

    self.delegate = self;
    self.dataSource = self;
    
    
    BdTV *title = [[BdTV alloc]initWithFrame:CGRectMake(0, 0, PMW, 44)];

    title.backBtn.hidden = self.isHidden;
    title.backBtn.enabled = !self.isHidden;
    [title.backBtn setTag:11];
    [title.backBtn addTarget:self action:@selector(btnOnClick:) forControlEvents:UIControlEventTouchUpInside];
    [[title doneBtn] removeFromSuperview];
    [title setMianTitle:@"我的订单"];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:title];
    
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
        self.edgesForExtendedLayout = UIRectEdgeNone;
    }
    
    if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {
        
        self.navigationController.navigationBar.tintColor = UIColorFromRGB(0xfd2e2f);
    } else {
        self.navigationController.navigationBar.barTintColor = UIColorFromRGB(0xfd2e2f);
    }

}


-(void)btnOnClick:(UIButton*)sender{
    if (sender.tag == 11) {
        [self.navigationController popViewControllerAnimated:YES];
    }

}


#pragma mark - ViewPagerDataSource
- (NSUInteger)numberOfTabsForViewPager:(ViewPagerController *)viewPager {
    return 3;
}


- (UIView *)viewPager:(ViewPagerController *)viewPager viewForTabAtIndex:(NSUInteger)index {
    
    UILabel *lable = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, ([UIScreen mainScreen ].applicationFrame.size.width)/3, 36)];
    lable.backgroundColor = [UIColor clearColor];
    lable.font = [UIFont systemFontOfSize:15.0];
    lable.textAlignment = NSTextAlignmentCenter;
    lable.textColor = [UIColor redColor];
    
    UIView *line = [[UIView alloc]init];
    [line setBackgroundColor:UIColorFromRGB(0xe3e3e3)];
    
    if (index==0) {
        
        lable1=lable;
        lable1.text = @"全部";
        
        return lable1;

    }else if(index==1){
        
        lable2=lable;
        lable2.text = @"交易中";
        return lable2;

    }else if (index==2){
        
        lable3=lable;
        lable3.text = @"已完成";
        return lable3;
    }
    
    return lable;
}


- (UIViewController *)viewPager:(ViewPagerController *)viewPager contentViewControllerForTabAtIndex:(NSUInteger)index {
    
    MyOrderSubVc *cvc = [[MyOrderSubVc alloc]init];
    cvc.nvc = self.navigationController;
    
    if(index==0){
    
        cvc.state = Order_State_all;
        cvc.countLab = lable1;
        
    }else if (index==1) {
        cvc.state = Order_State_ing;
        cvc.countLab = lable2;
    }else if (index==2){
        cvc.state=Order_State_finish;
        cvc.countLab = lable3;
    }

    return cvc;
}


#pragma mark - ViewPagerDelegate
- (UIColor *)viewPager:(ViewPagerController *)viewPager colorForComponent:(ViewPagerComponent)component withDefault:(UIColor *)color {
    
    switch (component) {
        case ViewPagerIndicator:
            
            return [UIColor redColor];
            break;
            
        case ViewPagerTabsView:
            
            return [UIColor whiteColor];
            break;
        
        default:
            break;
    }
    
    return color;
}


-(CGFloat)viewPager:(ViewPagerController *)viewPager valueForOption:(ViewPagerOption)option withDefault:(CGFloat)value{

    if (option==ViewPagerOptionTabWidth) {
        return ([UIScreen mainScreen ].applicationFrame.size.width)/3 ;
    }else if(option==ViewPagerOptionTabHeight){
        return 36;
    }
    return value;
}


- (void)viewPager:(ViewPagerController *)viewPager didChangeTabToIndex:(NSUInteger)index{
    
    if (index==0) {
        [lable1 setTextColor:[UIColor redColor]];
        [lable2 setTextColor:UIColorFromRGB(0x333333)];
        [lable3 setTextColor:UIColorFromRGB(0x333333)];
//        [lable1 setAttributedText:[NSString makeLineStyle:lable1.text color:[UIColor redColor] fontSize:14]];
//        [lable2 setAttributedText:[NSString makeLineStyle:lable2.text color:UIColorFromRGB(0x333333) fontSize:14]];
//        [lable3 setAttributedText:[NSString makeLineStyle:lable3.text color:UIColorFromRGB(0x333333) fontSize:14]];
    }else if (index==1){
    
        [lable1 setTextColor:UIColorFromRGB(0x333333)];
        [lable2 setTextColor:[UIColor redColor]];
        [lable3 setTextColor:UIColorFromRGB(0x333333)];
//        [lable2 setAttributedText:[NSString makeLineStyle:lable2.text color:[UIColor redColor] fontSize:14]];
//        [lable1 setAttributedText:[NSString makeLineStyle:lable1.text color:UIColorFromRGB(0x333333) fontSize:14]];
//        [lable3 setAttributedText:[NSString makeLineStyle:lable3.text color:UIColorFromRGB(0x333333) fontSize:14]];
    }else{
    
        [lable1 setTextColor:UIColorFromRGB(0x333333)];
        [lable2 setTextColor:UIColorFromRGB(0x333333)];
        [lable3 setTextColor:[UIColor redColor]];
//        [lable3 setAttributedText:[NSString makeLineStyle:lable3.text color:[UIColor redColor] fontSize:14]];
//        [lable1 setAttributedText:[NSString makeLineStyle:lable1.text color:UIColorFromRGB(0x333333) fontSize:14]];
//        [lable2 setAttributedText:[NSString makeLineStyle:lable2.text color:UIColorFromRGB(0x333333) fontSize:14]];
    }
}



@end
